<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>添加考勤</title>
  <meta name="viewport"
    content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  <meta name="format-detection" content="telephone=no,email=no,date=no,address=no" />
  <link rel="stylesheet" type="text/css" href="../../css/api.css" />
  <link rel="stylesheet" type="text/css" href="../../css/globle.css" />
  <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css" />
  <link rel="stylesheet" type="text/css" href="../../css/common.css" />
  <style>
    /* body {
      padding-top: 25px;
    } */

    span {
      margin: 10px;
    }

    .Tabl {
      height: 50px;
      width: 88%;
      font-size: 14px;
      font-weight: bold;
      text-align: left;
      margin-left: 6%;
    }

    .Td1 {
      color: #B8B8B8;
      width: 110px;
    }

    .Td2 {
      color: #000000;
      text-align: left;
    }

    .Hr {
      height: 1px;
      width: 96%;
      background-color: #B8B8B8;
      margin-left: 2%;
    }

    .Butt {
      border: 1px solid #B8B8B8;
      border-radius: 20px;
      color: #FFFFFF;
      height: 17px;
      width: 17px;
      outline: none;
    }

    .TabImg {
      height: 150px;
      width: 96%;
      margin-left: 2%;
      border: 10px solid #D8D8D8;
    }

    .TdImg1 {
      height: 110px;
      width: 90px;
    }

    .TdImg2 {
      height: 110px;
      width: 90px;
    }

    .ButAdd {
      height: 110px;
      width: 100px;
      font-size: 100px;
      color: #FFFFFF;
      background-color: #B8B8B8;
    }

    .TabL {
      height: 75px;
      width: 88%;
      font-size: 16px;
      font-weight: bold;
      text-align: left;
      margin-left: 6%;
    }

    .ButL {
      height: 40px;
      width: 100%;
      background-color: #1abc9c;
      /* position: fixed; */
      bottom: 0;
    }

    .Td3 {
      text-align: center;
      width: 50%;
    }

    select {
      appearance: none;
      -moz-appearance: none;
      -webkit-appearance: none;
      border: none;
      background: none;
    }
  </style>
</head>

<body id="body">
  <form action="" id="myform">
    <input type="hidden" id="id" name="id">
    <input type="hidden" name="a_tid" id="a_tid">
    <input type="hidden" name="a_area_id" id="a_area_id">
    <input type="hidden" name="a_project_id" id="a_project_id">
    <input type="hidden" name="a_eid" id="a_eid">
    <button style="background-color: #F2F2F2;height: 40px;width: 100%;font-size: 18px;">签到信息</button>
    <table class="Tabl">
      <tr>
        <td class="Td1">日期</td>
        <td class="Td2">
          <input id="a_createDate" name="a_createDate" />
        </td>
      </tr>
    </table>
    <hr class="Hr" />
    <table class="Tabl">
      <tr>
        <td class="Td1">施工队伍</td>
        <td class="Td2">
          <input id="a_name" name="a_name" />
        </td>
      </tr>
    </table>
    <hr class="Hr" />
    <table class="Tabl">
      <tr>
        <td class="Td1">应到人数</td>
        <td class="Td2">
          <input placeholder="请输入应到人数" type="number" name="a_should_num" id="a_should_num" />
        </td>
      </tr>
    </table>
    <button style="background-color: #F2F2F2;height: 40px;width: 100%;font-size: 18px;">上午签到信息</button>
    <table class="Tabl">
      <tr>
        <td class="Td1">上午人数</td>
        <td class="Td2">
          <input type="number" placeholder="请输入上午人数" name="a_am_num" id="a_am_num" />
        </td>
      </tr>
    </table>
    <hr class="Hr" />
    <table class="Tabl" id="signAmTime">
      <tr>
        <td class="Td1">签到时间</td>
        <td class="Td2">
          <input readonly id="a_am_createDate" name="a_am_createDate" />
        </td>
      </tr>
    </table>
    <hr class="Hr" />
    <div style="padding: 10px;">
      <ul class="upload-ul clearfix">
        <li class="upload-pick">
          <div class="webuploader-container clearfix" id="goodsUpload"></div>
        </li>
        <li>
          <div id="imgBoxAm" name="a_am_picture"></div>
        </li>
      </ul>
    </div>

    <div id="pm">

      <button style="background-color: #F2F2F2;height: 40px;width: 100%;font-size: 18px;">下午签到信息</button>

      <table class="Tabl">
        <tr>
          <td class="Td1">下午人数</td>
          <td class="Td2">
            <input type="number" name="a_pm_num" placeholder="请输入下午人数" id="a_pm_num" />
          </td>
        </tr>
      </table>
      <hr class="Hr" />
      <table class="Tabl" id="signPmTime">
        <tr>
          <td class="Td1">签到时间</td>
          <td class="Td2">
            <input id="a_pm_createDate" name="a_pm_createDate" />
          </td>
        </tr>
      </table>

      <div style="padding: 10px;" id="pm">
        <ul class="upload-ul clearfix">
          <li class="upload-pick">
            <div class="webuploader-container clearfix" id="imagePmUpload"></div>
          </li>
          <li>
            <div id="imgBoxPm" name="a_pm_picture"></div>
          </li>
        </ul>
      </div>
    </div>
    <table class="ButL">
      <tr>
        <td class="Td3">
          <div style="color: #ffffff;" onclick="postData()">
            发布
          </div>
        </td>
      </tr>
    </table>
  </form>
</body>
<script type="text/javascript" src="../../script/vue.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script src="../../script/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="../../script/diyUpload1.js" type="text/javascript"></script>
<script src="../../script/webuploader.js" type="text/javascript"></script>
<script type="text/javascript">
  //上传上午图片
  var uploadAmImage_url = BaseServiceUrl + "mobile/attendanceCon/uploadAmImage.json"
  var $tgaUpload = $("#goodsUpload").diyUpload({
    url: uploadAmImage_url,
    success: function (data) {
      //alert(JSON.stringify(data))
    },
    error: function (err) {
      alert(JSON.stringify(err));
    },
    buttonText: "",
    accept: {
      title: "Images",
      extensions: "gif,jpg,jpeg,bmp,png",
      mimeTypes: 'image/*'
    },
    thumb: {
      width: 600,
      height: 600,
      quality: 100,
      allowMagnify: false,
      crop: false,
      type: "image/jpeg",
    },
  });
  var uploadPmImage_url = BaseServiceUrl + "mobile/attendanceCon/uploadPmImage.json"
  var $tgaPmUpload = $("#imagePmUpload").diyUpload({
    url: uploadPmImage_url,
    success: function (data) {
      //alert(JSON.stringify(data))
    },
    error: function (err) {
      alert(JSON.stringify(err));
    },
    buttonText: "",
    accept: {
      title: "Images",
      extensions: "gif,jpg,jpeg,bmp,png",
      mimeTypes: 'image/*'
    },
    thumb: {
      width: 600,
      height: 600,
      quality: 100,
      allowMagnify: false,
      crop: false,
      type: "image/jpeg",
    },
  });
  $tgaPmUpload.options.formData.did = null;
  $tgaUpload.options.formData.dids = null;

  apiready = function () {
    var user = $api.getStorage("userSession");
    var areaId = user.data.areaid;
    var proId = user.data.projectid;
    var userId = user.data.id;
    ////企业id
    var enterpriseId = user.data.enterprise.id;
    var userName = user.data.name
    var roleId = user.data.sysRole.sysRoleCode.id;
    $("#body").hide()
    api.showProgress({
      title: '拼命加载中...',
      modal: false
    });
    $("#a_eid").val(enterpriseId)
    $("#a_tid").val(user.data.team_id)
    $("#a_area_id").val(areaId)
    $("#a_project_id").val(proId)
    $("#a_name").val(userName);
    var id = api.pageParam.id;
    // alert(typeof id);
    api.ajax(
      {
        url: BaseServiceUrl + "mobile/attendanceAdmin/findOne.json",
        method: "post",
        data: {
          values: {
            id: id,
          },
        },
        timeout: 30,
        dataType: "json",
        returnAll: false,
      },
      function (ret, err) {
        var data = ret.obj;
        // alert(JSON.stringify(data))
        if (null !== data.a_pm_createDate) {
          loadData1(data);
          api.hideProgress()
          $("#body").show()
        } else {
          loadData(data);
          api.hideProgress();
          $("#body").show()
        }
      }
    );
    //给添加下午的赋值
    function loadData(data) {
      // alert(JSON.stringify(data))
      $("#id").val(data.id);
      $("#a_createDate").val(data.a_createDate);
      $("#a_should_num").val(data.a_should_num);
      $("#a_am_num").val(data.a_am_num);
      $("#a_pm_num").val(data.a_pm_num);
      $("#a_am_createDate").val(data.a_am_createDate);
      $("#imgBoxAm").val(data.a_am_picture)
      if (null !== data.a_am_picture) {
        $("#imgBoxAm").append(
          '<div style="margin-left:5px;float:left;margin-top:5px;"><img width="100" height="100"   src="' +
          BaseServiceUrl + data.a_am_picture + '"></div>'
        );
      }
      $("#signAmTime").show()
      $("#signPmTime").hide()
    }

    //下午进行考勤 完毕
    function loadData1(data) {
      $("#id").val(data.id);
      $("#a_createDate").val(data.a_createDate);
      $("#a_should_num").val(data.a_should_num);
      $("#a_am_num").val(data.a_am_num);
      $("#a_pm_num").val(data.a_pm_num);
      $("#a_pm_createDate").val(data.a_pm_createDate);
      $("#a_am_createDate").val(data.a_am_createDate);
      $("#imgBoxAm").val(data.a_am_picture);
      $("#imgBoxPm").val(data.a_pm_picture);
      if (null !== data.a_am_picture) {
        $("#imgBoxAm").append(
          '<div style="margin-left:5px;float:left;margin-top:5px;"><img width="100" height="100"   src="' +
          serverImage +
          data.a_am_picture +
          '"\/><\/div>'
        );
      }
      if (null !== data.a_pm_picture) {
        $("#imgBoxPm").append(
          '<div style="margin-left:5px;float:left;margin-top:5px;"><img width="100" height="100"   src="' +
          serverImage + data.a_pm_picture +
          '"\/><\/div>'
        );
      }
      $("#signPmTime").show()
    }
  };



  function postData() {
    var user = $api.getStorage("userSession").data
    var a_tid = user.team_id;
    var roleId = user.sysRole.sysRoleCode.id;
    var t_count;
    $.ajax({
      url: BaseServiceUrl + "mobile/attendanceCon/findTeam.json",
      type: "POST",
      data: {
        a_tid: a_tid,
        role_id: roleId
      },
      async: false,
      dataType: "json",
      success: function (ret) {
        if (ret.code == 0) {
          t_count = ret.obj.t_count;
        }
      },
      error: function (jqXHR, textStatus, errorThrown) {
      }
    });
    //获取当前队伍最大施工人数

    //alert(a_tid)
    var formObject = {};
    var formArray = $("#myform").ghostsf_serialize();
    $.each(formArray, function (i, item) {
      formObject[item.name] = item.value;
    });
    var shouldnum = parseInt($("#a_should_num").val());
    var amnum = parseInt($("#a_am_num").val());
    var count = parseInt(t_count);
    if (shouldnum > count) {
      // api.msg("当前施工队伍最大施工人数为" + count + "人");
      api.alert({
        title: "提示",
        msg: "当前施工队伍最大施工人数为" + count + "人"
      });
      return false;
    }
    if (amnum > shouldnum) {//上午人数大于应到人数
      api.alert({
        title: '提示',
        msg: '上午考勤人数不得大于应到人数'
      });
      return false;
    } else if (amnum <= shouldnum) {//上午人数小于等于应到人数
      post(JSON.stringify(formObject));
      return false;
    }
    var a_pm_num = $("#a_pm_num").val()
    if (a_pm_num != "") {
      var pmnum = parseInt(a_pm_num);
      if (pmnum > shouldnum) {
        api.alert({
          title: '提示',
          msg: '下午考勤人数不得大于应到人数'
        });
        return false;
      } else if (pmnum <= shouldnum) {
        post(JSON.stringify(formObject));
        return false;
      }
    }
    // post(JSON.stringify(formObject))
    return false;
  }



  $.fn.ghostsf_serialize = function () {
    var a = this.serializeArray();
    var $radio = $("input[type=radio],input[type=checkbox]", this);
    var temp = {};
    $.each($radio, function () {
      if (!temp.hasOwnProperty(this.name)) {
        if ($("input[name='" + this.name + "']:checked").length == 0) {
          temp[this.name] = "";
          a.push({
            name: this.name,
            value: "",
          });
        }
      }
    });
    return a;
  };

  function post(data) {
    // alert(JSON.stringify(data))
    //return;
    api.showProgress({
      //打开开关
      title: "提交中...",
      text: "",
    });
    // alert(data)
    $.ajax({
      type: "post",
      //async : false, //同步执行
      url: BaseServiceUrl + "mobile/attendanceCon/update.json",
      data: {
        data: data
      },
      dataType: "json", //返回数据形式为json
      success: function (result) {
        //alert(JSON.stringify(result));
        $tgaUpload.options.formData.dids = result.obj.id
        $tgaPmUpload.options.formData.did = result.obj.id
        $tgaUpload.upload();
        $tgaPmUpload.upload()
        //alert(JSON.stringify(result))
        if (result.code == 0) {
          setTimeout(function () {
            api.closeWin();
            api.sendEvent({
              name: 'update',
              extra: {

              }
            });
          }, 5000);
        }
      },
      error: function (e) {
        alert(JSON.stringify(e))
      }
    });
  }
</script>

</html>